package com.bxl.chooser.client;

import com.bxl.chooser.bean.ChooseResponseMsg;

import java.util.concurrent.TimeUnit;

/**
 * <>
 *
 * @author baixl
 * @date 2021/3/29
 */
public class Main {
    public static void main(String[] args) {
        Client client = new Client("localhost", 9090);
        String[] messageIds ={"6070916940302228825","8445880571920186386","6491389194930948195","7678197081396561183"};
        for (String messageId : messageIds) {
            ChooseResponseMsg chooseResponseMsg = client.qryMsg(messageId);
            if(chooseResponseMsg.getCode().equals("1000")){
                System.out.println("messageId:"+chooseResponseMsg.getMessageId()+" content:"+chooseResponseMsg.getMsgContent());
            }
        }
        


        Thread a = new Thread(() -> {
            for (int i = 0; i < 100; i++) {
                try {
                    ChooseResponseMsg msg = client.sengMsg(String.valueOf(i));
                    if (msg.getCode().equals(ChooseResponseMsg.success.getCode())) {
                        System.out.println(String.format("%s 发送成功", i));
                    }

                    //TimeUnit.SECONDS.sleep(3);
                } catch (RuntimeException e) {
                    e.printStackTrace();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

        Thread b = new Thread(() -> {
            for (int i = 100; i < 200; i++) {
                try {
                    ChooseResponseMsg msg = client.sengMsg(String.valueOf(i));
                    if (msg.getCode().equals(ChooseResponseMsg.success.getCode())) {
                        System.out.println(String.format("%s 发送成功", i));
                    }

                    //TimeUnit.SECONDS.sleep(3);
                } catch (RuntimeException e) {
                    e.printStackTrace();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

        Thread c = new Thread(() -> {
            for (int i = 200; i < 300; i++) {
                try {
                    ChooseResponseMsg msg = client.sengMsg(String.valueOf(i));
                    if (msg.getCode().equals(ChooseResponseMsg.success.getCode())) {
                        System.out.println(String.format("%s 发送成功", i));
                    }

                    //TimeUnit.SECONDS.sleep(3);
                } catch (RuntimeException e) {
                    e.printStackTrace();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

        a.start();
        b.start();
        c.start();


    }
}
